#include "../../Common/Detail.hpp"
#include "../../Client/RpcClient.hpp"
#include <thread>

void CallBack(const Json::Value& json)
{
    std::cout << json.asInt() << std::endl;
}

int main()
{
    // 1. 创建一个rpc客户端，用于连接服务端进行rpc调用
    // false -- 不进行服务发现
    RpcModule::ClientModule::RpcClient::ptr client = std::make_shared<RpcModule::ClientModule::RpcClient>(false, "127.0.0.1", 9090);
    // 2. 同步发送请求测试
    Json::Value params;
    params["num1"] = 11;
    params["num2"] = 22;
    Json::Value result;
    client->Call("Add", params, result);
    std::cout << "同步测试结果为：" << result.asInt() << std::endl;
    // 3. 异步发送请求测试
    RpcModule::ClientModule::RpcCaller::JsonAsyncResponse future;
    params["num1"] = 22;
    params["num2"] = 33;
    client->Call("Add", params, future);
    std::cout << "异步测试结果为：" << future.get().asInt() << std::endl;
    // 4. 回调函数发送请求测试
    params["num1"] = 33;
    params["num2"] = 44;
    client->Call("Add", params, CallBack);

    std::this_thread::sleep_for(std::chrono::seconds(6));
    return 0;
}